|
|
Am 05.12.2018 um 16:43 schrieb ingo:
> I tried to use it to not render test scenes in an include file when the
> file is included instead of stand alone. Didn't succeed so far, only
> acheived the opposite result.
The simplest way to check whether your file is included or loaded as a
main scene file is to set a certain variable wherever you include the
file, and in the file itself test whether that variable is set, like so:
// some scene file
#declare FooIncluded = true;
#include "foo.pov"
// foo.pov
#if (FooIncluded)
// This is the main scene file.
#else
// This is an included file.
#end
Alternatively, you can detect whether you're in the main scene file by
exploiting the fact that local variables in the main scene file are
actually global. Here are two such hacks (untested, but the concepts
should work):
(1) This one sets a global variable, then sets a local variable of the
same name. In an include file this will create an additional variable
that just "eclipses" the global one, while in the main file this will
change the variable. To test which of these happened, the "most local"
variable is then destroyed again. In an include file this will just
destroy the local variable, revealing the global variable again; in the
main file, it will instead destroy the single global=local variable,
leaving the variable name undefined:
// foo.pov
#declare FooIncludeTest = true;
#local FooIncludeTest = true;
#undef FooIncludeTest
#ifdef (FooIncludeTest)
#undef FooIncludeTest
// We're included (or in a macro)
#else
// We're the main scene file (outside any macros)
#end
Note that the global variable must be declared first; if a local
variable of the same name already exists, `#declare` will change that
variable instead of defining a global variable.
(2) This one is a bit more elegant, but requires POV-Ray v3.8-alpha. It
sets a local variable, then uses the pseudo-dictionary `global` to check
whether that variable ended up as a global variable:
// foo.pov
#local FooIncludeTest = true;
#ifdef (global.FooIncludeTest)
// We're the main scene file (outside any macros)
#else
// We're included (or in a macro)
#end
Post a reply to this message
|
|